package com.qyj.spring_boot_02.service.Impl;

import com.alibaba.fastjson.JSONObject;
import com.qyj.spring_boot_02.bean.*;
import com.qyj.spring_boot_02.mapper.clickhouse.DataMapper;
import com.qyj.spring_boot_02.mapper.mysql.MysqlDataMapper;
import com.qyj.spring_boot_02.service.DataService;
import com.qyj.spring_boot_02.util.NumberExtractorUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@Service
@Component
public class DataServiceImpl implements DataService {
    private static final ArrayList<String> MYLOCATION = new ArrayList<String>(Arrays.asList("贵州","云南","天津","上海","重庆","河北","河南","浙江","辽宁","黑龙江","湖南","安徽","山东","新疆","江苏"));
    @Autowired
    DataMapper dataMapper;
    @Autowired
    MysqlDataMapper mysqlDataMapper;
    @Value("${spNum}")
    private Integer spNum;
    @Override
    public JSONObject getShangPing() {
        JSONObject jsonObject = JSONObject.parseObject("{}");
        List<SpPlCountNum> spPlCountNumList = dataMapper.getSpPlCountNumList();
        Long spN = 0L;
        Long plN = 0L;
        for (SpPlCountNum t: spPlCountNumList) {
            jsonObject.put(t.getName(),t.getCount());
            if(t.getId() == 1){
                spN = t.getCount();
            }
            if (t.getId() == 2){
                plN = t.getCount();
            }
        }
        jsonObject.put("平均评论量", plN / spN);
        jsonObject.put("产品数量", spNum);
        return jsonObject;
    }

    @Override
    public JSONObject getNameSkuClassList() {
//        List<SkuClassName> skuClassName = dataMapper.getSkuClassName();
        List<SkuClassName> skuClassName = mysqlDataMapper.getSkuClassName();
        JSONObject jsonObject = JSONObject.parseObject("{}");
        ArrayList<String> nameList = new ArrayList<>();
        ArrayList<String> skuClassList = new ArrayList<>();
        ArrayList<String> splitNameList = new ArrayList<>();
        HashMap<String, String> skuClassWithname = new HashMap<>();
        HashMap<String, String> skuClassWithJianName = new HashMap<>();

        int size = skuClassName.size();
        if (size >= spNum){
            size = spNum;
        }
        for (int i = 0; i < size; i++) {
            SkuClassName t = skuClassName.get(i);
            nameList.add(t.getName());
            skuClassWithname.put(t.getSkuClass(),t.getName());
            String jianName = t.getName().split("（")[0];
            splitNameList.add(jianName);
            skuClassWithJianName.put(t.getSkuClass(),jianName);
            skuClassList.add(t.getSkuClass());
        }
        jsonObject.put("name",nameList);
        jsonObject.put("classWithNameDict",skuClassWithname);
        jsonObject.put("classWithJianNameDict",skuClassWithJianName);
        jsonObject.put("jianName",splitNameList);
        jsonObject.put("skuClass",skuClassList);
        return jsonObject;
    }

    @Override
    public JSONObject getTimeCount(Integer month) {
        List<TimePingLunCount> timePingLunCountList = dataMapper.getTimePingLunCountList();
        JSONObject jsonObject = JSONObject.parseObject("{}");
        ArrayList<String> data = new ArrayList<>();
        ArrayList<Long> value = new ArrayList<>();
        int size = timePingLunCountList.size();
        if(month > size - spNum){
            month = 0;
        }
        int start = 0;
        if(size > spNum){
            start = size - spNum;
        }
        for (int i = start-month; i < size-month; i++) {
            try {
                data.add(timePingLunCountList.get(i).getTime());
                value.add(timePingLunCountList.get(i).getPingLunCount());
            }catch (Exception e){
                e.printStackTrace();
                System.out.println("getTimeCount 无色废弃");
            }
        }
        jsonObject.put("data",data);
        jsonObject.put("value",value);
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("鸟数据类型","用户画像评论时间");
        jsonObject1.put("data",jsonObject);
        return jsonObject1;
    }

    @Override
    public JSONObject getPriceRangeCount() {
        List<PriceRangeBean> priceRange = dataMapper.getPriceRange();
        JSONObject jsonObject =new JSONObject() ;
        ArrayList<String> data = new ArrayList<>();
        ArrayList<Long> valueCount = new ArrayList<>();
        ArrayList<Double> valuePriceSum = new ArrayList<>();
        for (PriceRangeBean t: priceRange) {
            data.add(t.getPriceQj());
            valueCount.add(t.getCount());
            valuePriceSum.add(t.getPriceSum());
        }
        jsonObject.put("data",data);
        jsonObject.put("valueCount",valueCount);
        jsonObject.put("valuePriceSum",valuePriceSum);
        return jsonObject;
    }

    @Override
    public JSONObject getPeizhiKeyWord(Integer page) {
        if(page==null || page == 0){
            page = 1;
        }
        Integer pageNum = spNum;
        List<PeizhiKeyWordBean> peizhiKeyWord = dataMapper.getPeizhiKeyWord((page - 1) * pageNum,pageNum);
        JSONObject jsonObject =new JSONObject() ;
        ArrayList<String> data = new ArrayList<>();
        ArrayList<Long> valueCount = new ArrayList<>();
        for (PeizhiKeyWordBean t:peizhiKeyWord){
            data.add(t.getKeyWord());
            valueCount.add(t.getCount());
        }
        jsonObject.put("data",data);
        jsonObject.put("valueCount",valueCount);
        return jsonObject;
    }

    @Override
    public JSONObject getPingLunKeyWord(Integer page) {
        if(page == 0){
            page = 1;
        }
        List<PingLunkeyWordCountBean> pingLunKeyWordCount = dataMapper.getPingLunKeyWordCount((page - 1) * spNum, spNum);
        JSONObject jsonObject =new JSONObject() ;
        ArrayList<String> data = new ArrayList<>();
        ArrayList<Long> valueCount = new ArrayList<>();
        for (PingLunkeyWordCountBean t:pingLunKeyWordCount){
            data.add(t.getKeyWord());
            valueCount.add(t.getCount());
        }
        jsonObject.put("data",data);
        jsonObject.put("valueCount",valueCount);
        return jsonObject;
    }

    @Override
    public JSONObject getPingPaiPingLunCount() {
        List<PingPaifenLeiBean> pinPaifenLeiChangPing = dataMapper.getPinPaifenLeiChangPing();
        List<PingPaifenLeiBean> pinPaifenLeiPingLun = dataMapper.getPinPaifenLeiPingLun();
        JSONObject jsonObject = new JSONObject();
        ArrayList<String> skuClass = new ArrayList<>();
        ArrayList<Long> pingLun = new ArrayList<>();
        ArrayList<Long> changP = new ArrayList<>();
        int size = pinPaifenLeiChangPing.size();
        if (size >= spNum){
            size = spNum;
        }
        for (int i = 0; i < size; i++) {
            skuClass.add(pinPaifenLeiChangPing.get(i).getSkuClass());
            pingLun.add(pinPaifenLeiPingLun.get(i).getCount());
            changP.add(pinPaifenLeiChangPing.get(i).getCount());
        }
        jsonObject.put("商品类型",skuClass);
        jsonObject.put("cp分类的评论量",pingLun);
        jsonObject.put("cp分类的产品量",changP);
        return jsonObject;
    }

    @Override
    public JSONObject getSkuHaoPingAvg() {
        List<SkuHaoPingAvgBean> skuHaoPingAvgBean = dataMapper.getSkuHaoPingAvgBean();
        JSONObject jsonObject = new JSONObject();
        ArrayList<String> skuClass = new ArrayList<>();
        ArrayList<Integer> avgHao = new ArrayList<>();
        ArrayList<String> name = new ArrayList<>();
        int size = skuHaoPingAvgBean.size();
        if(size >= spNum){
            size = spNum;
        }
        for (int i = 0; i < size; i++) {
            skuClass.add(skuHaoPingAvgBean.get(i).getSkuClass());
            avgHao.add(skuHaoPingAvgBean.get(i).getAvgHao());
            name.add(dataMapper.getSkuNameWithSkuClass(skuHaoPingAvgBean.get(i).getSkuClass()).split("（")[0]);
        }
        jsonObject.put("品牌类型",skuClass);
        jsonObject.put("品牌名称",name);
        jsonObject.put("好评率",avgHao);
        return jsonObject;
    }

    @Override
    public JSONObject getSkuXiaoCountService() {
        List<SkuXiaoCount> skuXiaoCount = dataMapper.getSkuXiaoCount();
        JSONObject jsonObject = new JSONObject();
        ArrayList<String> skuClass = new ArrayList<>();
        ArrayList<Long> count = new ArrayList<>();
        int size = skuXiaoCount.size();
        if(size >= spNum){
            size = spNum;
        }
        for (int i = 0; i < size; i++) {
            skuClass.add(dataMapper.getSkuNameWithSkuClass(skuXiaoCount.get(i).getSkuClass()).split("（")[0]);
            count.add(skuXiaoCount.get(i).getCount());
        }
        jsonObject.put("品牌名称",skuClass);
        jsonObject.put("销量",count);
        return jsonObject;
    }

    @Override
    public JSONObject getLocationCountService(Integer year) {
        if(year==null){
            year = 0;
        }
        List<Integer> yearIsInTableList = dataMapper.getYearIsInTableList();
        int size = yearIsInTableList.size();
        if(year==0 || ! yearIsInTableList.contains(year)){
            StringBuilder stringBuilder = new StringBuilder();
            for (int i = 0; i < size; i++) {
                if(i == size - 1){
                    stringBuilder.append(yearIsInTableList.get(i));
                }else{
                    stringBuilder.append(yearIsInTableList.get(i)).append(",");
                }
            }
            String yearList = new String(stringBuilder);
            List<LocationCountBean> locationCountMapper = dataMapper.getLocationCountMapper(yearList);
            ArrayList<String> locations = new ArrayList<>();
            ArrayList<Long> counts = new ArrayList<>();
            ArrayList<Long> pingluns = new ArrayList<>();
            JSONObject jsonObject = new JSONObject();
            for (LocationCountBean t:locationCountMapper) {
//                if(MYLOCATION.contains(t.getLocation())) {
                    locations.add(t.getLocation());
                    counts.add(t.getCount());
                    pingluns.add(t.getXiaoCount());
//                }
            }
            jsonObject.put("地区名称",locations);
            jsonObject.put("countValue",counts);
            jsonObject.put("xiaoCountValue",pingluns);
            JSONObject resJSON = new JSONObject();
            resJSON.put("全部数据",jsonObject);
            return resJSON;
        }else{
            List<LocationCountBean> locationCountMapper = dataMapper.getLocationCountMapper(String.valueOf(year));
            ArrayList<String> locations = new ArrayList<>();
            ArrayList<Long> counts = new ArrayList<>();
            ArrayList<Long> pingluns = new ArrayList<>();
            JSONObject jsonObject = new JSONObject();
            for (LocationCountBean t:locationCountMapper) {
//                if(MYLOCATION.contains(t.getLocation())) {
                    locations.add(t.getLocation());
                    counts.add(t.getCount());
                    pingluns.add(t.getXiaoCount());
//                }
            }
            jsonObject.put("地区名称",locations);
            jsonObject.put("countValue",counts);
            jsonObject.put("xiaoCountValue",pingluns);
            JSONObject resJSON = new JSONObject();
            resJSON.put(year+"年的数据",jsonObject);
            return resJSON;
        }

    }

    @Override
    public List<LocationDateXiaoLiang> getDataFenXiWithLocationDateXiaoLiang() {
        return dataMapper.getLocationDateXiaoLiang();
    }

    @Override
    public JSONObject getLocationCountQd(Integer year, String jidu) {
        List<LocationCountBean> locationCountQdNumXiaoLiang = dataMapper.getLocationCountQdNumXiaoLiang(year, jidu);
        ArrayList<String> locations = new ArrayList<>();
        ArrayList<Long> counts = new ArrayList<>();
        ArrayList<Long> pingluns = new ArrayList<>();
        JSONObject jsonObject = new JSONObject();
        for (LocationCountBean t:locationCountQdNumXiaoLiang) {
            if(!t.getLocation().equals("未知")) {

                locations.add(t.getLocation());
                counts.add(t.getCount());
                pingluns.add(t.getXiaoCount());
            }
        }
        jsonObject.put("地区名称",locations);
        jsonObject.put("countValue",counts);
        jsonObject.put("xiaoCountValue",pingluns);
        JSONObject resJSON = new JSONObject();
        resJSON.put(year+"年"+jidu+"的数据",jsonObject);
        return resJSON;
    }

    @Override
    public JSONObject getPinPaiXiaoLiangService(Integer year, String jidu) {
        List<PinPaiCountXiaoBean> pinPaiCountXiaoBean = dataMapper.getPinPaiCountXiaoBean(year, jidu);
        ArrayList<String> skuNames = new ArrayList<>();
        ArrayList<Long> counts = new ArrayList<>();
        ArrayList<Long> pingluns = new ArrayList<>();
        JSONObject jsonObject = new JSONObject();
        int size = pinPaiCountXiaoBean.size();
        if(size >= spNum){
            size = spNum;
        }
        for (int i=0;i < size ; i++){
            PinPaiCountXiaoBean t = pinPaiCountXiaoBean.get(i);
            String s = dataMapper.getSkuNameWithSkuClass(t.getSkuClass()).split("（")[0];
            skuNames.add(s);
            counts.add(t.getCount());
            pingluns.add(t.getXiaoCount());
        }
        jsonObject.put("品牌简称",skuNames);
        jsonObject.put("countValue",counts);
        jsonObject.put("xiaoCountValue",pingluns);
        JSONObject resJSON = new JSONObject();
        resJSON.put(year+"年"+jidu+"的数据",jsonObject);
        return resJSON;
    }

    @Override
    public JSONObject getShiYinWithTheTimeService(String year, String jidu, Integer page, Integer pageNum) {
        if(pageNum == null || pageNum <= 0 ){
            pageNum = spNum;
        }
        if (page == null || page <= 0){
           page = 1;
        }
        List<ShiyinWithTimeBean> shiyinWithTimeBeanList = dataMapper.getShiyinWithTimeBeanList(year, jidu, (page - 1) *pageNum, pageNum);
        int size = shiyinWithTimeBeanList.size();
        ArrayList<String> keywords = new ArrayList<>();
        ArrayList<Long> counts = new ArrayList<>();
        for (int i=0;i < size; i ++ ){
            ShiyinWithTimeBean t = shiyinWithTimeBeanList.get(i);
            keywords.add(t.getKeyWord());
            counts.add(t.getCount());
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("keywords",keywords);
        jsonObject.put("values",counts);
        JSONObject jsonReturn = new JSONObject();
        jsonReturn.put(year+"年"+jidu+"的数据",jsonObject);
        return jsonReturn;
    }

    @Override
    public JSONObject getKeshihuaData() {
        List<TimeForCountBean> keshihuaData = dataMapper.getKeshihuaData();
        ArrayList<String> years = new ArrayList<>();
        ArrayList<Long> counts = new ArrayList<>();
        int start = keshihuaData.size() - 10;
        if (start < 0){
            start = 0;
        }

        for (int i = start; i < keshihuaData.size(); i++) {
            TimeForCountBean t = keshihuaData.get(i);
            years.add(t.getYear() + "年"+t.getQuarter().substring(0,1));
            counts.add(t.getCount());
        }
        // TODO  666666
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("年季度",years);
        jsonObject.put("values",counts);
        return jsonObject;
    }

    @Override
    public JSONObject getjiageQUJianAnPinPaiService(String skuClass) {
        List<String> allskuClass = dataMapper.getAllskuClass();
        if(!allskuClass.contains(skuClass)){
            // TODO 不合法的
            List<SkuClassName> skuClassName = dataMapper.getSkuClassName();
            JSONObject jsonObject = JSONObject.parseObject("{}");
            ArrayList<String> nameList = new ArrayList<>();
            ArrayList<String> skuClassList = new ArrayList<>();
            ArrayList<String> splitNameList = new ArrayList<>();
            HashMap<String, String> skuClassWithname = new HashMap<>();
            HashMap<String, String> skuClassWithJianName = new HashMap<>();
            for (SkuClassName t:skuClassName) {
                nameList.add(t.getName());
                skuClassWithname.put(t.getSkuClass(),t.getName());
                String jianName = t.getName().split("（")[0];
                splitNameList.add(jianName);
                skuClassWithJianName.put(t.getSkuClass(),jianName);
                skuClassList.add(t.getSkuClass());
            }
            jsonObject.put("name",nameList);
            jsonObject.put("classWithNameDict",skuClassWithname);
            jsonObject.put("classWithJianNameDict",skuClassWithJianName);
            jsonObject.put("jianName",splitNameList);
            jsonObject.put("skuClass",skuClassList);
            return jsonObject;
        }
        List<PriceRangeQjBean> priceRangeBeanList = dataMapper.getPriceRangeQjBeanList(skuClass);
        JSONObject jsonObject = new JSONObject();
        ArrayList<String> names = new ArrayList<>();
        ArrayList<Double> priceSum = new ArrayList<>();
        ArrayList<Long> counts = new ArrayList<>();
        ArrayList<Long> xiaoCount = new ArrayList<>();
        String skuName = dataMapper.getSkuNameWithSkuClass(skuClass).split("（")[0];
        int size = priceRangeBeanList.size();
        for (int i = 0; i < size; i++) {
            PriceRangeQjBean t = priceRangeBeanList.get(i);
            names.add(t.getPriceQj());
            priceSum.add(t.getPriceSum());
            counts.add(t.getCount());
            xiaoCount.add(t.getXiaoCount());
        }
        jsonObject.put("价格区间",names);
        jsonObject.put("数量",counts);
        jsonObject.put("销量",xiaoCount);
        jsonObject.put("销量金额",priceSum);
        JSONObject jsonReturn = new JSONObject();
        jsonReturn.put("品牌",skuName);
        jsonReturn.put("data",jsonObject);
        return jsonReturn;
    }

    @Override
    public JSONObject getTimeCountWithSkuClass(String skuClass) {
        List<String> allskuClass = dataMapper.getAllskuClass();
        if(!allskuClass.contains(skuClass)){
            // TODO 不合法的
            List<SkuClassName> skuClassName = dataMapper.getSkuClassName();
            JSONObject jsonObject = JSONObject.parseObject("{}");
            ArrayList<String> nameList = new ArrayList<>();
            ArrayList<String> skuClassList = new ArrayList<>();
            ArrayList<String> splitNameList = new ArrayList<>();
            HashMap<String, String> skuClassWithname = new HashMap<>();
            HashMap<String, String> skuClassWithJianName = new HashMap<>();
            for (SkuClassName t:skuClassName) {
                nameList.add(t.getName());
                skuClassWithname.put(t.getSkuClass(),t.getName());
                String jianName = t.getName().split("（")[0];
                splitNameList.add(jianName);
                skuClassWithJianName.put(t.getSkuClass(),jianName);
                skuClassList.add(t.getSkuClass());
            }
            jsonObject.put("name",nameList);
            jsonObject.put("classWithNameDict",skuClassWithname);
            jsonObject.put("classWithJianNameDict",skuClassWithJianName);
            jsonObject.put("jianName",splitNameList);
            jsonObject.put("skuClass",skuClassList);
            return jsonObject;
        }
        List<TimeCountAndXiaoCount> timeCountWithSkuClass = dataMapper.getTimeCountWithSkuClass(skuClass);
        ArrayList<String> times = new ArrayList<>();
        ArrayList<String> skuNames = new ArrayList<>();
        ArrayList<Long> counts = new ArrayList<>();
        ArrayList<Double> priceSums = new ArrayList<>();
        ArrayList<Long> xiaoCounts = new ArrayList<>();
        String skuName = dataMapper.getSkuNameWithSkuClass(skuClass).split("（")[0];
        int size = timeCountWithSkuClass.size();
        for (int i = 0; i < size; i++) {
            TimeCountAndXiaoCount t = timeCountWithSkuClass.get(i);
            times.add(t.getTime());
            counts.add(t.getCount());
            priceSums.add(t.getPriceSum());
            xiaoCounts.add(t.getXiaoCount());
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("time",times);
        jsonObject.put("count",counts);
        jsonObject.put("priceSum",priceSums);
        jsonObject.put("xiaoCount",xiaoCounts);
        JSONObject jsonReturn = new JSONObject();
        jsonReturn.put("品牌名称",skuName);
        jsonReturn.put("data",jsonObject);
        return jsonReturn;
    }

    @Override
    public JSONObject getSelectLocationWhereSkuClassBeanListService(String skuClass) {
        List<String> allskuClass = dataMapper.getAllskuClass();
        if(!allskuClass.contains(skuClass)){
            // TODO 不合法的
            List<SkuClassName> skuClassName = dataMapper.getSkuClassName();
            JSONObject jsonObject = JSONObject.parseObject("{}");
            ArrayList<String> nameList = new ArrayList<>();
            ArrayList<String> skuClassList = new ArrayList<>();
            ArrayList<String> splitNameList = new ArrayList<>();
            HashMap<String, String> skuClassWithname = new HashMap<>();
            HashMap<String, String> skuClassWithJianName = new HashMap<>();
            for (SkuClassName t:skuClassName) {
                nameList.add(t.getName());
                skuClassWithname.put(t.getSkuClass(),t.getName());
                String jianName = t.getName().split("（")[0];
                splitNameList.add(jianName);
                skuClassWithJianName.put(t.getSkuClass(),jianName);
                skuClassList.add(t.getSkuClass());
            }
            jsonObject.put("name",nameList);
            jsonObject.put("classWithNameDict",skuClassWithname);
            jsonObject.put("classWithJianNameDict",skuClassWithJianName);
            jsonObject.put("jianName",splitNameList);
            jsonObject.put("skuClass",skuClassList);
            return jsonObject;
        }
        List<SelectLocationWhereSkuClassBean> selectLocationWhereSkuClassBeanList = dataMapper.getSelectLocationWhereSkuClassBeanList(skuClass);
        ArrayList<String> locations = new ArrayList<>();
        ArrayList<Long> counts = new ArrayList<>();
        ArrayList<Double> priceSums = new ArrayList<>();
        ArrayList<Long> xiaoCounts = new ArrayList<>();
        String skuName = dataMapper.getSkuNameWithSkuClass(skuClass).split("（")[0];
        int size = selectLocationWhereSkuClassBeanList.size();
        for (int i = 0; i < size; i++) {
            SelectLocationWhereSkuClassBean t = selectLocationWhereSkuClassBeanList.get(i);
            locations.add(t.getLocation());
            counts.add(t.getCount());
            priceSums.add(t.getPriceSum());
            xiaoCounts.add(t.getXiaoCount());
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("locations",locations);
        jsonObject.put("count",counts);
        jsonObject.put("priceSum",priceSums);
        jsonObject.put("xiaoCount",xiaoCounts);
        JSONObject jsonReturn = new JSONObject();
        jsonReturn.put("品牌名称",skuName);
        jsonReturn.put("data",jsonObject);
        return jsonReturn;
    }

    @Override
    public JSONObject getgetSkuInfoProductAll(String skuClass,Integer page, Integer pageNum) {
        List<String> allskuClass = dataMapper.getAllskuClass();
        if(!allskuClass.contains(skuClass)){
            // TODO 不合法的
            List<SkuClassName> skuClassName = dataMapper.getSkuClassName();
            JSONObject jsonObject = JSONObject.parseObject("{}");
            ArrayList<String> nameList = new ArrayList<>();
            ArrayList<String> skuClassList = new ArrayList<>();
            ArrayList<String> splitNameList = new ArrayList<>();
            HashMap<String, String> skuClassWithname = new HashMap<>();
            HashMap<String, String> skuClassWithJianName = new HashMap<>();
            for (SkuClassName t:skuClassName) {
                nameList.add(t.getName());
                skuClassWithname.put(t.getSkuClass(),t.getName());
                String jianName = t.getName().split("（")[0];
                splitNameList.add(jianName);
                skuClassWithJianName.put(t.getSkuClass(),jianName);
                skuClassList.add(t.getSkuClass());
            }
            jsonObject.put("name",nameList);
            jsonObject.put("classWithNameDict",skuClassWithname);
            jsonObject.put("classWithJianNameDict",skuClassWithJianName);
            jsonObject.put("jianName",splitNameList);
            jsonObject.put("skuClass",skuClassList);
            return jsonObject;
        }

        ArrayList<SkuInfoProductAll> skuInfoProductAll = mysqlDataMapper.getSkuInfoProductAll("%" + skuClass + "%",page, pageNum);
        ArrayList<String> skuIds = new ArrayList<>();
        ArrayList<Double> prices = new ArrayList<>();
        ArrayList<String> names = new ArrayList<>();
        ArrayList<String> imgUrls = new ArrayList<>();
        ArrayList<String> evalTypes = new ArrayList<>();
        ArrayList<String> porViews = new ArrayList<>();
        ArrayList<String> evaluates = new ArrayList<>();
        ArrayList<String> proconfs = new ArrayList<>();
        ArrayList<String> dates = new ArrayList<>();
        ArrayList<String> locations = new ArrayList<>();
        for (int i = 0; i < skuInfoProductAll.size(); i++) {
            SkuInfoProductAll t = skuInfoProductAll.get(i);
            skuIds.add(t.getSkuId());
            prices.add(t.getPrice());
            names.add(t.getName());
            imgUrls.add(t.getImgUrl());
            evalTypes.add(t.getEvalType());
            porViews.add(( t.getPorView() == null)? "好评度90%" : t.getPorView());
            evaluates.add(t.getEvaluate());
            proconfs.add(t.getProconf());
            dates.add(t.getDate());
            locations.add(t.getLocation());
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("skuIds",skuIds);
        jsonObject.put("prices",prices);
        jsonObject.put("names",names);
        jsonObject.put("imgUrls",imgUrls);
        jsonObject.put("evalTypes",evalTypes);
        jsonObject.put("porViews",porViews);
        jsonObject.put("evaluates",evaluates);
        jsonObject.put("proconfs",proconfs);
        jsonObject.put("dates",dates);
        jsonObject.put("locations",locations);
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("dataList", jsonObject);
        return jsonObject1;
    }

    @Override
    public JSONObject getGetKeyWordBySkuClassBean(String skuClass, Integer page, Integer pageNum) {
        List<String> allskuClass = dataMapper.getAllskuClass();
        if(!allskuClass.contains(skuClass)){
            // TODO 不合法的
            List<SkuClassName> skuClassName = dataMapper.getSkuClassName();
            JSONObject jsonObject = JSONObject.parseObject("{}");
            ArrayList<String> nameList = new ArrayList<>();
            ArrayList<String> skuClassList = new ArrayList<>();
            ArrayList<String> splitNameList = new ArrayList<>();
            HashMap<String, String> skuClassWithname = new HashMap<>();
            HashMap<String, String> skuClassWithJianName = new HashMap<>();
            for (SkuClassName t:skuClassName) {
                nameList.add(t.getName());
                skuClassWithname.put(t.getSkuClass(),t.getName());
                String jianName = t.getName().split("（")[0];
                splitNameList.add(jianName);
                skuClassWithJianName.put(t.getSkuClass(),jianName);
                skuClassList.add(t.getSkuClass());
            }
            jsonObject.put("name",nameList);
            jsonObject.put("classWithNameDict",skuClassWithname);
            jsonObject.put("classWithJianNameDict",skuClassWithJianName);
            jsonObject.put("jianName",splitNameList);
            jsonObject.put("skuClass",skuClassList);
            return jsonObject;
        }
        List<GetKeyWordBySkuClassBean> getKeyWordBySkuClass = dataMapper.getGetKeyWordBySkuClass(skuClass, page, pageNum);
        String skuNameWithSkuClass = dataMapper.getSkuNameWithSkuClass(skuClass);
        ArrayList<String> keyword = new ArrayList<>();
        ArrayList<Long> count = new ArrayList<>();
        for (GetKeyWordBySkuClassBean t: getKeyWordBySkuClass) {
            keyword.add(t.getKeyword());
            count.add(t.getCount());
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("dataKeyWord",keyword);
        jsonObject.put("counts",count);
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("品牌名字",skuNameWithSkuClass);
        jsonObject1.put("data",jsonObject);
        return jsonObject1;
    }

    @Override
    public JSONObject getSkuInfoWhereSkuClassService(String skuClass, Integer page, Integer pageNum) {
        List<String> allskuClass = dataMapper.getAllskuClass();
        if(!allskuClass.contains(skuClass)){
            // TODO 不合法的
            List<SkuClassName> skuClassName = dataMapper.getSkuClassName();
            JSONObject jsonObject = JSONObject.parseObject("{}");
            ArrayList<String> nameList = new ArrayList<>();
            ArrayList<String> skuClassList = new ArrayList<>();
            ArrayList<String> splitNameList = new ArrayList<>();
            HashMap<String, String> skuClassWithname = new HashMap<>();
            HashMap<String, String> skuClassWithJianName = new HashMap<>();
            for (SkuClassName t:skuClassName) {
                nameList.add(t.getName());
                skuClassWithname.put(t.getSkuClass(),t.getName());
                String jianName = t.getName().split("（")[0];
                splitNameList.add(jianName);
                skuClassWithJianName.put(t.getSkuClass(),jianName);
                skuClassList.add(t.getSkuClass());
            }
            jsonObject.put("name",nameList);
            jsonObject.put("classWithNameDict",skuClassWithname);
            jsonObject.put("classWithJianNameDict",skuClassWithJianName);
            jsonObject.put("jianName",splitNameList);
            jsonObject.put("skuClass",skuClassList);
            return jsonObject;
        }
        String skuNameWithSkuClass = dataMapper.getSkuNameWithSkuClass(skuClass);
        ArrayList<XiaoLiangHaopingBean> xiaoLiangHaopingBean = mysqlDataMapper.getXiaoLiangHaopingBean(skuClass, page * pageNum, pageNum);
        ArrayList<Double> priceList = new ArrayList<>();
        ArrayList<String> nameList = new ArrayList<>();
        ArrayList<String> imgUrlList = new ArrayList<>();
        ArrayList<Long> evalTypeList = new ArrayList<>();
        ArrayList<Integer> porViewList = new ArrayList<>();
        for (XiaoLiangHaopingBean t:xiaoLiangHaopingBean) {
            priceList.add(t.getPrice());
            nameList.add(t.getName());
            imgUrlList.add(t.getImgUrl());
            String evalType = t.getEvalType();
            if (evalType == null || evalType.equals("") || evalType.equals("新品上市")){
                evalType = "10000";
            }else {
                String s = null;
                try {
                    s = NumberExtractorUtil.get(evalType);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if (s == null){
                    evalType = "10000";
                }else {
                    if(evalType.contains("万")){
                        evalType = String.valueOf(Long.parseLong(s) * 10000L);
                    }else {
                        evalType = s;
                    }
                }
            }
            evalTypeList.add(Long.valueOf(evalType));
            String porView = t.getPorView();
            if (porView == null || porView.equals("")){
                porView = "98";
            }else {
                String s = null;
                try {
                    s = NumberExtractorUtil.get(porView);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if (s==null){
                    porView = "98";
                }else {
                    porView = s;
                }
            }
            porViewList.add(Integer.valueOf(porView));
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("priceList",priceList);
        jsonObject.put("nameList",nameList);
        jsonObject.put("imgUrlList",imgUrlList);
        jsonObject.put("evalTypeList",evalTypeList);
        jsonObject.put("porViewList",porViewList);
        JSONObject res = new JSONObject();
        res.put("品牌名称",skuNameWithSkuClass);
        res.put("dataList",jsonObject);
        return res;
    }
}
